package stack;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.PriorityQueue;

public class MinStack {
    Deque<Integer> stack;
    PriorityQueue<Integer> pqueue;

    public MinStack() {
        stack = new ArrayDeque<>();
        pqueue = new PriorityQueue<>();
    }

    public void push(int val) {
        stack.push(val);
        pqueue.offer(val);
    }

    public void pop() {
        Integer item = stack.pop();
        //删除对应的
        pqueue.remove(item);
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return pqueue.peek();
    }

    public static void main(String[] args) {
        // MinStack obj = new MinStack();
        MinStack minStack = new MinStack();
        minStack.push(-2);
        minStack.push(0);
        minStack.push(-3);
        System.out.println(minStack.getMin());
        minStack.pop();
        System.out.println(minStack.top());
        System.out.println(minStack.getMin());
    }
}
